#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>

using std::cout;
using std::endl;
using std::for_each;
using std::remove_if;
using std::copy;
using std::vector;
using std::ostream_iterator;

bool func(int value)
{
    return value > 4;
}

void test()
{
    vector<int> vec = {1, 3, 4, 6, 8, 5, 3, 2};
    for_each(vec.begin(), vec.end(), [](int &value){
             cout << value << "  ";
             });
    cout << endl;

    //remove_if不能将满足条件的元素一次删除，需要配合erase
    //使用
    /* auto it = remove_if(vec.begin(), vec.end(), */ 
    /*                     bind1st(std::less<int>(), 4)); */

    auto it = remove_if(vec.begin(), vec.end(), 
                        bind2nd(std::greater<int>(), 4));

    /* auto it = remove_if(vec.begin(), vec.end(), [](int value){ */
    /*                     return value > 4; */
    /*                     }); */
    /* auto it = remove_if(vec.begin(), vec.end(), func); */
    vec.erase(it, vec.end());
    for_each(vec.begin(), vec.end(), [](int &value){
             cout << value << "  ";
             });
    cout << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

